In [1]:
import numpy as np
In [5]:
a=np.ones((5,5))
a
Out[5]:
array([[1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.]])
In [6]:
a=np.ones((5,5),dtype='int')
a
Out[6]:
array([[1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1]])
In [8]:
b=np.zeros((3,3),dtype='int')
b
Out[8]:
array([[0, 0, 0],
       [0, 0, 0],
       [0, 0, 0]])
In [9]:
a * 255
Out[9]:
array([[255, 255, 255, 255, 255],
       [255, 255, 255, 255, 255],
       [255, 255, 255, 255, 255],
       [255, 255, 255, 255, 255],
       [255, 255, 255, 255, 255]])
In [10]:
import matplotlib.pyplot as plt # Library used for visualization
In [11]:
%matplotlib inline 
plt.rcParams['figure.figsize'] = 8,3
In [17]:
from PIL import Image #python image library
In [18]:
car_img=Image.open(r'C:\Users\dassa\Downloads\WallPapers\car.jpg')
In [19]:
car_img
Out[19]:
No description has been provided for this image
In [20]:
type(car_img)
Out[20]:
PIL.JpegImagePlugin.JpegImageFile
In [21]:
car_arr= np.asarray(car_img)  # converted images to Array
car_arr
Out[21]:
array([[[ 30,  12,   2],
        [ 31,  13,   3],
        [ 32,  14,   4],
        ...,
        [ 42,  40,   0],
        [ 43,  41,   0],
        [ 44,  42,   1]],

       [[ 31,  13,   3],
        [ 31,  13,   3],
        [ 32,  14,   4],
        ...,
        [ 44,  42,   1],
        [ 45,  43,   2],
        [ 46,  44,   3]],

       [[ 31,  13,   3],
        [ 32,  14,   4],
        [ 32,  14,   4],
        ...,
        [ 46,  44,   3],
        [ 48,  46,   5],
        [ 49,  47,   6]],

       ...,

       [[ 45,  41,  32],
        [ 46,  42,  33],
        [ 46,  42,  33],
        ...,
        [ 97,  71,  56],
        [ 98,  72,  57],
        [ 99,  73,  58]],

       [[ 40,  36,  27],
        [ 41,  37,  28],
        [ 41,  37,  28],
        ...,
        [100,  74,  59],
        [100,  74,  59],
        [101,  75,  58]],

       [[ 38,  34,  25],
        [ 39,  35,  26],
        [ 40,  36,  27],
        ...,
        [103,  75,  61],
        [103,  76,  59],
        [104,  77,  60]]], dtype=uint8)
In [22]:
type(car_arr)
Out[22]:
numpy.ndarray
In [23]:
car_arr.shape
Out[23]:
(2160, 3840, 3)
In [26]:
plt.imshow(car_arr)
plt.show()
No description has been provided for this image
In [27]:
car2_copy=car_arr.copy()
In [28]:
car2_copy
Out[28]:
array([[[ 30,  12,   2],
        [ 31,  13,   3],
        [ 32,  14,   4],
        ...,
        [ 42,  40,   0],
        [ 43,  41,   0],
        [ 44,  42,   1]],

       [[ 31,  13,   3],
        [ 31,  13,   3],
        [ 32,  14,   4],
        ...,
        [ 44,  42,   1],
        [ 45,  43,   2],
        [ 46,  44,   3]],

       [[ 31,  13,   3],
        [ 32,  14,   4],
        [ 32,  14,   4],
        ...,
        [ 46,  44,   3],
        [ 48,  46,   5],
        [ 49,  47,   6]],

       ...,

       [[ 45,  41,  32],
        [ 46,  42,  33],
        [ 46,  42,  33],
        ...,
        [ 97,  71,  56],
        [ 98,  72,  57],
        [ 99,  73,  58]],

       [[ 40,  36,  27],
        [ 41,  37,  28],
        [ 41,  37,  28],
        ...,
        [100,  74,  59],
        [100,  74,  59],
        [101,  75,  58]],

       [[ 38,  34,  25],
        [ 39,  35,  26],
        [ 40,  36,  27],
        ...,
        [103,  75,  61],
        [103,  76,  59],
        [104,  77,  60]]], dtype=uint8)
In [29]:
car2_copy==car_arr
Out[29]:
array([[[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       ...,

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]],

       [[ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True],
        ...,
        [ True,  True,  True],
        [ True,  True,  True],
        [ True,  True,  True]]])
In [30]:
plt.imshow(car2_copy)
plt.show()
No description has been provided for this image
In [31]:
car2_copy.shape
Out[31]:
(2160, 3840, 3)
In [33]:
plt.imshow(car2_copy[:,:,0]) # RGB
plt.show()
No description has been provided for this image
In [34]:
car2_copy[:,:,0]  # Array Values
Out[34]:
array([[ 30,  31,  32, ...,  42,  43,  44],
       [ 31,  31,  32, ...,  44,  45,  46],
       [ 31,  32,  32, ...,  46,  48,  49],
       ...,
       [ 45,  46,  46, ...,  97,  98,  99],
       [ 40,  41,  41, ..., 100, 100, 101],
       [ 38,  39,  40, ..., 103, 103, 104]], dtype=uint8)
In [38]:
plt.imshow(car2_copy[:,:,0] , cmap='BuPu_r') # colur mapping cmap
plt.show()
No description has been provided for this image
In [39]:
plt.imshow(car2_copy[:,:,1] , cmap='BuPu_r') # colur mapping cmap
plt.show()
No description has been provided for this image
In [43]:
plt.imshow(car2_copy[:,:,2] , cmap='BuPu_r') # colur mapping cmap
plt.show()
No description has been provided for this image
In [44]:
car2_copy[:,:,0]
Out[44]:
array([[ 30,  31,  32, ...,  42,  43,  44],
       [ 31,  31,  32, ...,  44,  45,  46],
       [ 31,  32,  32, ...,  46,  48,  49],
       ...,
       [ 45,  46,  46, ...,  97,  98,  99],
       [ 40,  41,  41, ..., 100, 100, 101],
       [ 38,  39,  40, ..., 103, 103, 104]], dtype=uint8)
In [45]:
car2_copy[:,:,1]
Out[45]:
array([[12, 13, 14, ..., 40, 41, 42],
       [13, 13, 14, ..., 42, 43, 44],
       [13, 14, 14, ..., 44, 46, 47],
       ...,
       [41, 42, 42, ..., 71, 72, 73],
       [36, 37, 37, ..., 74, 74, 75],
       [34, 35, 36, ..., 75, 76, 77]], dtype=uint8)
In [46]:
car2_copy[:,:,2]
Out[46]:
array([[ 2,  3,  4, ...,  0,  0,  1],
       [ 3,  3,  4, ...,  1,  2,  3],
       [ 3,  4,  4, ...,  3,  5,  6],
       ...,
       [32, 33, 33, ..., 56, 57, 58],
       [27, 28, 28, ..., 59, 59, 58],
       [25, 26, 27, ..., 61, 59, 60]], dtype=uint8)
In [48]:
plt.imshow(car2_copy)
plt.show()
No description has been provided for this image
In [49]:
car2_copy[:,:,2] =0
In [50]:
car2_copy[:,:,2]
Out[50]:
array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       ...,
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
In [51]:
plt.imshow(car2_copy)
plt.show()
No description has been provided for this image
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: